package org.example.demo.monitor;

import io.opentelemetry.exporter.logging.LoggingSpanExporter;
import io.opentelemetry.exporter.prometheus.PrometheusHttpServer;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.trace.SdkTracerProvider;
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoMonitorApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoMonitorApplication.class, args);

        int prometheusPort = 9999;
//        Resource resource =
//                Resource.getDefault()
//                        .merge(Resource.builder().put("test", "PrometheusExporterExample").build());

        OpenTelemetrySdk openTelemetrySdk =
                OpenTelemetrySdk.builder()
                        .setMeterProvider(
                                SdkMeterProvider.builder()
                                        .setResource( Resource.getDefault() )
                                        .registerMetricReader(
                                                PrometheusHttpServer.builder().setPort(prometheusPort).build())
                                        .build())
                        .buildAndRegisterGlobal();

        Runtime.getRuntime().addShutdownHook(new Thread(openTelemetrySdk::close));

    }

}
